package com.mf.morefun.start;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import com.mf.morefun.R;
import com.mf.morefun.base.BaseBusActivity;
import com.mf.morefun.constant.Configuration;
import com.mf.morefun.ui.HomePagerActivity;
import com.mf.morefun.ui.userinfo.LoginActivity;
import com.zhcx.zhcxlibrary.utils.DateUtils;
import com.zhcx.zhcxlibrary.utils.SPUtils;
import com.zhcx.zhcxlibrary.utils.StringUtils;

import java.text.ParseException;
import java.util.Date;

public class StartPagerActivity extends BaseBusActivity{
    private SPUtils mSputils;
    @Override
    protected int getNaviteColor() {
        return 0;
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_startpager;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        if((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0){
            finish();
            return;
        }
        mSputils = new SPUtils(getApplicationContext());
//        try {
//            long time = DateUtils.DATE_YEAR_MONTH_DAY.parse("2019-05-20").getTime();
//            if (System.currentTimeMillis() >= time){
//                finish();
//            }
//        } catch (ParseException e) {
//            e.printStackTrace();
//            finish();
//        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                //
                loadInMain();
            }
        }, 2000);
        Intent intent = new Intent();
        intent.setAction("HeartbeatService");
        intent.setPackage("com.mf.morefun"); //指定启动的是那个应用（lq.cn.twoapp）中的Action(b.aidl.DownLoadService)指向的服务组件
        startService(intent);
    }

    private void loadInMain() {
        Intent mIntent = null;
        if (StringUtils.isEmpty(mSputils.getString(Configuration.USERID))){
            mIntent = new Intent(StartPagerActivity.this, LoginActivity.class);
        }else {
            mIntent = new Intent(StartPagerActivity.this, HomePagerActivity.class);
        }
        startActivity(mIntent);
        finish();
    }

    @Override
    protected void initData() {

    }
}
